﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;

namespace WFTest
{
   
         
    public partial class Form2 : Form
    {

        public Form2()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string oldPath = this.textBox1.Text;
            string newPath = this.textBox2.Text;
            if (!Directory.Exists(newPath)) {
                try
                {
                    Directory.CreateDirectory(newPath);
                }
                catch (Exception)
                {
                    MessageBox.Show("请输入正确的路径");
                }
                IEnumerable<string> ies= Directory.EnumerateFiles(oldPath);
                foreach (string item in ies)
                {
                    string newstr = newPath + item.Substring(item.LastIndexOf("\\"));
                   
                File.Copy(item, newstr, true);
                }
            }
            else{
                IEnumerable<string> ies = Directory.EnumerateFiles(oldPath);
                foreach (string item in ies)
                {
                    string newstr = newPath + item.Substring(item.LastIndexOf("\\"));
                   
                File.Copy(item, newstr, true);
                }

            }
        }
    }
}
